﻿using System.Collections;

namespace Encloser
{
    public static class ValidUtils
    {
        public static bool IsEmpty(params object[] param)
        {
            if (param == null) return true;
            if (param.Length == 0) return false;
            foreach (var item in param)
            {
                if (TestObject(item, false)) return true;
            }
            return false;
        }

        public static bool HasEmpty(params object[] param)
        {
            if (param == null) return true;
            if (param.Length == 0) return false;
            foreach (var item in param)
            {
                if (TestObject(item, true)) return true;
            }
            return false;
        }

        private static bool TestObject(object val, bool deep)
        {
            if (val == null) return true;
            if (val is string) return (val as string).Length == 0;
            if (val is IEnumerable)
            {
                var flag = true;
                foreach (var item in val as IEnumerable)
                {
                    if (!deep) return false;
                    if (TestObject(item, true)) return true;
                    flag = false;
                }
                return flag;
            }
            return false;
        }
    }
}
